package start.spring.basic.report.controller.filltemplete;

import java.util.List;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.security.annotation.RequiresPermissions;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import start.spring.basic.log.ServiceLog;
import start.spring.basic.page.PageQuery;
import start.spring.basic.report.common.SysConstant;
import start.spring.basic.report.controller.BaseController;
import start.spring.basic.report.entity.ReportFillData;
import start.spring.basic.report.service.filltemplete.IReportFillDataService;
import start.spring.basic.report.vo.filltemplete.FillDataInfo;
import start.spring.basic.response.ResponseData;
import start.spring.basic.response.ResponsePage;

/**
 * 
 * @author xyy
 * @date 2024-01-16
 *
 */
@RestController
@RequestMapping("/filldata")
@Api(tags = "填报数据相关接口")
public class ReportFillDataController extends BaseController {
	
    @Autowired
    private IReportFillDataService reportFillDataService;
	
    @ServiceLog(businessType = "查询填报数据列表", systemType = SysConstant.SYSTEM_TYPE, recordResult = false, userId = "")
    @RequiresPermissions("report:filldata:list")
    @PostMapping("/list")
    @ApiOperation(value = "查询填报数据列表", notes = "分页查询")
    public ResponsePage<ReportFillData> list(PageQuery pageQuery, @RequestBody ReportFillData reportFillData) {
    	return super.returnResponse(this.reportFillDataService.selectReportFillDataPageList(pageQuery, reportFillData));
    }
    
    @ServiceLog(businessType = "查询填报数据详情", systemType = SysConstant.SYSTEM_TYPE, recordResult = true, userId = "")
    @RequiresPermissions("report:filldata:list")
    @PostMapping("/detail")
    @ApiOperation(value = "查询填报数据详情", notes = "同步返回模板信息")
    public ResponseData<FillDataInfo> detail(@RequestBody ReportFillData reportFillData) {
    	return this.reportFillDataService.selectReportFillDataDetail(reportFillData);
    }
	
    @ServiceLog(businessType = "保存填报数据草稿", systemType = SysConstant.SYSTEM_TYPE, recordResult = true, userId = "")
    @RequiresPermissions("report:filldata:add")
    @PostMapping("/savedraft")
    @ApiOperation(value = "保存填报数据草稿", notes = "")
    public ResponseData<String> saveDraft(@RequestBody ReportFillData reportFillData) {
        return this.reportFillDataService.saveDraft(reportFillData);
    }
    
    @ServiceLog(businessType = "修改填报数据", systemType = SysConstant.SYSTEM_TYPE, recordResult = true, userId = "")
    @RequiresPermissions("report:filldata:edit")
    @PostMapping("/edit")
    @ApiOperation(value = "修改填报数据", notes = "")
    public ResponseData<Integer> edit(@RequestBody ReportFillData reportFillData) {
    	return ResponseData.successData(this.reportFillDataService.updateReportFillData(reportFillData));
    }
    
    @ServiceLog(businessType = "提交填报数据", systemType = SysConstant.SYSTEM_TYPE, recordResult = true, userId = "")
    @RequiresPermissions("report:filldata:add")
    @PostMapping("/commit")
    @ApiOperation(value = "提交填报数据", notes = "")
    public ResponseData<String> commitData(@RequestBody ReportFillData reportFillData) {
        return this.reportFillDataService.commitData(reportFillData);
    }
	
    @ServiceLog(businessType = "删除填报数据", systemType = SysConstant.SYSTEM_TYPE, recordResult = true, userId = "")
    @RequiresPermissions("report:filldata:remove")
    @PostMapping("/remove")
    @ApiOperation(value = "删除填报数据", notes = "")
    public ResponseData<String> remove(@RequestBody List<Long> dataIds) {
    	return this.reportFillDataService.deleteReportFillDataByDataIds(dataIds);
    }
    
    @ServiceLog(businessType = "导出填报数据列表", systemType = SysConstant.SYSTEM_TYPE, recordResult = false, userId = "")
    @RequiresPermissions("report:filldata:export")
    @PostMapping("/export")
    @ApiOperation(value = "导出填报数据列表", notes = "")
    public void export(HttpServletResponse response, ReportFillData reportFillData) {
        List<ReportFillData> list = this.reportFillDataService.selectReportFillDataList(reportFillData);
        ExcelUtil<ReportFillData> util = new ExcelUtil<ReportFillData>(ReportFillData.class);
        util.exportExcel(response, list, "填报数据数据");
    }
}
